app.controller('brandController', function ($scope, $controller, brandService) {
    $controller('baseController', {$scope: $scope})

    $scope.brandInfo = function (page, rows) {
        brandService.brandInfo(page, rows)
            .success(
                function (res) {
                    $scope.list = res.data.rows;
                }
            )
    }

    //新增品牌
    $scope.addInfo = function () {
        const editBrand = {
            name: $scope.name,
            firstChar: $scope.firstChar
        }
        brandService.addInfo(editBrand)
            .success(
                function (res) {
                    if (res.flag) {
                        alert('添加成功');
                        $scope.reloadList();
                    }
                }
            )
    }

    //展示编辑信息
    $scope.showEditInfo = function (brand) {
        $scope.id = brand.id;
        $scope.editName = brand.name;
        $scope.editFirstChar = brand.firstChar
    }

    //更新品牌
    $scope.editInfo = function () {
        const editBrand = {
            id: $scope.id,
            name: $scope.editName,
            firstChar: $scope.editFirstChar
        }
        brandService.editInfo(editBrand)
            .success(
                function (res) {
                    if (res.flag) {
                        alert('更新成功');
                        $scope.reloadList();
                    }
                }
            )
    }

    //删除
    $scope.deleteBrand = function () {
        const data = $scope.selectIds
        brandService.deleteBrand(data)
            .success(function (res) {
                if (res.flag) {
                    alert('删除成功')
                    $scope.reloadList();
                }
            })
    }


    //分页
    $scope.findPage = function (page, rows) {
        brandService.findPage(page, rows).success(
            function (response) {
                $scope.list = response.data.rows;
                $scope.paginationConf.totalItems = response.data.total;//更新总记录数
            }
        )

    }

    //清空表单

    $scope.clear = function () {
        $scope.name = ''
        $scope.firstChar = ''
    }

    //关键词查询
    $scope.searchEntity = {}
    $scope.search = function (page, rows) {
        brandService.search(page, rows,$scope.searchEntity).success(
            function (response) {
                $scope.list = response.data.rows;
                $scope.paginationConf.totalItems = response.data.total;//更新总记录数
            }
        )
    }
})